// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class ORDER_RGV_O15 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("27 ORC",27)]
  	    [HL7Field(HL7Version.v24, 27, HL7Repeat.False, HL7Required.True,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("28 ORDER_DETAIL",28)]
  	    [HL7Field(HL7Version.v24, 28, HL7Repeat.False, HL7Required.False,"ORDER_DETAIL_RGV_O15")]
	    public ORDER_DETAIL_RGV_O15 ORDER_DETAIL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("49 ENCODING",49)]
  	    [HL7Field(HL7Version.v24, 49, HL7Repeat.False, HL7Required.False,"ENCODING_RGV_O15")]
	    public ENCODING_RGV_O15 ENCODING {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("60 GIVE",60)]
  	    [HL7Field(HL7Version.v24, 60, HL7Repeat.True, HL7Required.True,"GIVE_RGV_O15")]
	    public GIVE_RGV_O15[] GIVE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
			ORDER_DETAIL = ProcessGroup<ORDER_DETAIL_RGV_O15>(availableData, options, "ORDER_DETAIL");
			ENCODING = ProcessGroup<ENCODING_RGV_O15>(availableData, options, "ENCODING");
			GIVE = ProcessGroupArray<GIVE_RGV_O15>(availableData, options, "GIVE");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isORC = availableData.StartsWith("ORC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ORC", options.Version) || isORC) {
				return isORC;
			}
			ORDER_DETAIL_RGV_O15 testORDER_DETAIL_RGV_O15 = new ORDER_DETAIL_RGV_O15();
			bool grpCCORDER_DETAIL_RGV_O15 = (testORDER_DETAIL_RGV_O15.CanConsume(availableData, options));
			if (IsRequired("ORDER_DETAIL", options.Version) || grpCCORDER_DETAIL_RGV_O15) {
				return grpCCORDER_DETAIL_RGV_O15;
			}
			ENCODING_RGV_O15 testENCODING_RGV_O15 = new ENCODING_RGV_O15();
			bool grpCCENCODING_RGV_O15 = (testENCODING_RGV_O15.CanConsume(availableData, options));
			if (IsRequired("ENCODING", options.Version) || grpCCENCODING_RGV_O15) {
				return grpCCENCODING_RGV_O15;
			}
			GIVE_RGV_O15 testGIVE_RGV_O15 = new GIVE_RGV_O15();
			bool grpCCGIVE_RGV_O15 = (testGIVE_RGV_O15.CanConsume(availableData, options));
			if (IsRequired("GIVE", options.Version) || grpCCGIVE_RGV_O15) {
				return grpCCGIVE_RGV_O15;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "ORDER";
			}
        }

        static ORDER_RGV_O15() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(ORDER_RGV_O15));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ORC != null) {
			string segmentValue = ORC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ORDER_DETAIL != null) {
			string segmentValue = ORDER_DETAIL.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ENCODING != null) {
			string segmentValue = ENCODING.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (GIVE != null && GIVE.Length > 0) {
			for (int i = 0; i < GIVE.Length; i++) {
				string segmentValue = GIVE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

